<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8"/>
	<meta name="keywords" content="syntax, style"/>
	<link rel="stylesheet" href="../../Shared/sty/standard.css"/>
	<script defer src="../../Shared/js/toc.js"></script>
	
	<title>Define syntax highlighting in CotEditor on Mac</title>
</head>

<body>
<a name="syntax_highlight_settings"></a>

<h1>Define syntax highlighting in CotEditor on Mac</h1>

<p>To define highlighting rules for a syntax, select a syntax element from the list on the sidebar of the syntax editor, then add highlighting conditions to the list on the right. For instructions on opening the syntax editor, see <a href="syntax_definition.html">Define a syntax</a>.</p>


<section>
<p>CotEditor already defines the element types used for syntax highlighting in each theme. These elements are:</p>

<table>
	<thead>
		<tr><th>Element</th><th>Description</th><th>Examples</th></tr>
	</thead>
	
	<tbody>
	<tr><th>Keywords</th>
	<td>Keywords in source code such as reserved words of programming languages.</td>
	<td><code>for</code>, <code>while</code>, <code>if</code></td></tr>
	
	<tr><th>Commands</th>
	<td>Functions or commands in source code.</td>
	<td><code>print</code>, <code>filter</code>, <code>func()</code></td></tr>
	
	<tr><th>Types</th>
	<td>Types in source code or headings in structured language.</td>
	<td><code>int</code>, <code>bool</code>, <code>Object</code></td></tr>
	
	<tr><th>Attributes</th>
	<td>Attributes in source code.</td>
	<td><code>&lt;html <span style="color:-apple-system-blue">lang</span>=&quot;ja&quot;&gt;</code>, <code>@classmethod</code></td></tr>
	
	<tr><th>Variables</th>
	<td>Variables in source code.</td>
	<td><code>$foo</code>, <code>self</code></td></tr>
	
	<tr><th>Values</th>
	<td>Value constants in source code.</td>
	<td><code>Null</code>, <code>True</code>, <code>False</code></td></tr>
	
	<tr><th>Numbers</th>
	<td>Numeric constants in source code.</td>
	<td><code>Int i = <span style="color: -apple-system-blue;">0</span>;</code></td></tr>
	
	<tr><th>Strings</th>
	<td>String constants in source code.</td>
	<td><code>String s = <span style="color: -apple-system-blue">&quot;Hello World&quot;</span></code></td></tr>
	
	<tr><th>Characters</th>
	<td>Character constants in source code.</td>
	<td><code>Char c = <span style="color: -apple-system-blue">'a'</span></code></td></tr>
	
	<tr><th>Comments</th>
	<td>Comments in source code.</td>
	<td><code>/* 〜 */</code>, <code># 〜</code></td></tr>
	</tbody>
</table>

<p>CotEditor colors syntax elements from top to bottom in the list, such as Keywords, Commands, and Types. If a document contains text that matches multiple categories (for example, both a keyword and a command) the style of the element that appears later in the order overrides the earlier one. The names of the elements are provided for reference and can also be used for other grammatical purposes.</p>
</section>


<section>
<h2>Define a syntax highlighting rule</h2>

<p>To define how text is highlighted, register one of the following as a highlighting condition for each element: a specific piece of text, a pair of start and end strings, or a regular expression pattern.</p>

<p>Highlighting rules are determined by the following settings:</p>

<table>
	<thead>
		<tr><th>Field</th><th>Description</th></tr>
	</thead>
	<tbody>
		<tr><th>RE</th><td>If selected, both the begin and end strings are treated as regular expressions (RE stands for Regular Expression).</td></tr>
		<tr><th>IC</th><td>If selected, the search ignores case (IC stands for Ignore Case). For example, if you set “abc” as the begin string and turn on IC, occurrences such as “ABC,” “abc,” and “aBc” in your document all match.</td></tr>
		<tr><th>Begin String</th><td>The text that marks the beginning of the search pattern. This field is required for defining a syntax element to highlight.</td></tr>
		<tr><th>End String</th><td>The text that marks the end of the search pattern. This field may be left blank.</td></tr>
		<tr><th>Description</th><td>A note or comment for your reference. The description doesn’t affect syntax highlighting and may be left blank.</td></tr>
	</tbody>
</table>

<p>By defining conditions:</p>
<ul>
	<li><p>A condition with an empty begin string is ignored.</p></li>
	<li><p>When RE is selected, both the begin and end strings are interpreted as regular expressions, meaning they must both be written either in regular expression pattern or in plain text.</p></li>
</ul>


<p>A condition whose end string is blank and whose regular expression option is not selected is also used for completion candidates.</p>
</section>


<section id="cf">
<h2>See also</h2>
<ul>
	<li><a href="syntax_definition.html">Define a syntax</a></li>
	<li><a href="about_regex.html">Use the regular expression</a></li>
</ul>
</section>

</body>
</html>
